package models

import (
	"strconv"
	"time"
)

type CarPortrait struct {
	Id              int       `xorm:"pk autoincr comment('id递增') BIGINT(11)"`
	CarId           int64     `xorm:"default 0 comment('车表中的关联id') BIGINT(11)"`
	InstitutionCode string    `form:"portrait_code" xorm:"default '' comment('运管统一编码') VARCHAR(16)"`
	ImageUrl        string    `form:"image_url" xorm:"default '' comment('图片路径') VARCHAR(255)"`
	CarLevel        string    `form:"image_url" xorm:"default '' comment('图片路径') VARCHAR(255)"`
	DrivingLicenseA string    `form:"driving_license_a" xorm:"default '' comment('行驶证A') VARCHAR(255)"`
	DrivingLicenseB string    `form:"driving_license_b" xorm:"default '' comment('行驶证B') VARCHAR(255)"`
	AddTime         time.Time `xorm:"comment('添加时间') DATETIME"`
}

func (c *CarPortrait) GetPortraitByCarId(id string) (list *CarPortrait, err error) {
	list = new(CarPortrait)
	if carid, err := strconv.ParseInt(id, 10, 64); err != nil {
		return list, err
	} else {
		if _, err = engine.Table("dts_car_portrait").Where("car_id = ?", carid).Get(list); err != nil {
			return list, err
		}
	}
	return list, nil
}
